package com.fll.config;


import com.fll.entity.CourseModel;
import com.fll.util.CrawUtil;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * 字段配置
 *
 * @Description
 * @Author fanlei
 * @Version 1.0
 * @Date 2018年09月12日
 */
public class FinalFieldConfig {

    public final static String RZ_ICON = "rz-icon";
    public final static String VIP_ICON = "vip-icon";
    public final static String PLAYERICON = "playericon";

    /**
     * 认证信息
     */
    public static final Map<String,String> map;

    /**
     * 下载视频输出路径
     */
    public static final String outFilePath = "D:/极客学院";
    /**
     * 爬取的信息输出路劲
     */
    public static final String infoPath = "/info";
    /**
     * 爬取并下载成功的信息输出路径
     */
    public static final String succePath = "/succe";

    public static final List<String> downType;

    static {
        //需要用的认证信息Cookie
        map = new HashMap<String, String>();
        map.put("Accept","application/json, text/javascript, */*; q=0.01");
        map.put("Accept-Encoding","gzip, deflate, br");
        map.put("Accept-Language","zh-CN,zh;q=0.9");
        map.put("Cookie",);
        map.put("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36");


        //需要下载的视频类型
        downType = new ArrayList<String>();
        downType.add(RZ_ICON);//认证专享
        downType.add(VIP_ICON);//VIP
        //downType.add(PLAYERICON);//普通



    }

    public static void main(String[] arg) throws IOException {


        CrawUtil.deleteFile(FinalFieldConfig.outFilePath + FinalFieldConfig.infoPath);

        CourseModel courseModel = new CourseModel();
        courseModel.setCourseDetailModels(null);
        courseModel.setTotal(1);
        courseModel.setCourseUrl("fdsfaf");
        CrawUtil.serializer(infoPath,courseModel);

        CourseModel o = (CourseModel)CrawUtil.reSerializer(succePath);
        System.out.println(String.format("%.3f", 55.0));
        if (true){
            return;
        }

        WebClient wc = new WebClient(BrowserVersion.CHROME);
        wc.getOptions().setUseInsecureSSL(true);
        wc.getOptions().setJavaScriptEnabled(true); // 启用JS解释器，默认为true
        wc.getOptions().setCssEnabled(false); // 禁用css支持
        wc.getOptions().setThrowExceptionOnScriptError(false); // js运行错误时，是否抛出异常
        wc.getOptions().setTimeout(100000); // 设置连接超时时间 ，这里是10S。如果为0，则无限期等待
        wc.getOptions().setDoNotTrackEnabled(false);
        HtmlPage page = wc.getPage("https://www.jikexueyuan.com/course/springmvc/");
        Document parse = Jsoup.parse(page.asXml());
        String s = parse.outerHtml();

        String url = "www.jikexueyuan.com/course/82332.html";
        System.out.println(url.substring(url.indexOf("course/")+7, url.lastIndexOf(".html")));
        /***************************/


        String a="共 9 页";
        String regEx="[^0-9]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(a);
        System.out.println( m.replaceAll("").trim());

        Scanner scanner = new Scanner(System.in);
        String tst = scanner.nextLine();
        Set<String> keys = CrawUtil.specialStrs.keySet();
        for (String key:
                keys) {
            tst = tst.replace(key, CrawUtil.specialStrs.get(key));
        }
        System.out.println(tst);
    }

}
